<?php session_start(); require_once('../connections/con_gl.php');require './phpmailer/PHPMailerAutoload.php'; ?>
<?php
$act = $_GET[act];
$url = "index.php?component=sretail";
echo $act;
mysql_select_db($database_con_gl, $con_gl);
$query_gudang = "SELECT * FROM gl_gudang where id='$_SESSION[lokasi]'";
$gudang = mysql_query($query_gudang, $con_gl) or die(mysql_error());
$row_gudang = mysql_fetch_assoc($gudang);

// -- validasi
if(($act =='add') || ($act == 'edit')) { 
	if (trim($_POST['noreferensi']) == '') {
		$error[] = '- No Referensi harus diisi !!!';
	}
	if (trim($_POST['tanggal']) == '') {
		$error[] = '- Tanggal harus diisi !!!';
	}
	if (trim($_POST['dari']) == '') {
		$error[] = '- Customer harus dipilih !!!';
	}
	if (trim($_POST['txtbarang']) == '') {
		$error[] = '- Paket Sewa harus dipilih !!!';
	}
	if (trim($_POST['txtkendaraan']) == '') {
		$error[] = '- Kendaraan harus dipilih !!!';
	}
	if (trim($_POST['txtemail']) == '') {
		$error[] = '- email pelanggan harap diisi !!!';
	}
	if (trim($_POST['jumlah']) < 1) {
		$error[] = '- Lama Sewa Tidak Valid !!!';
	}
	if (trim($_POST['txtpengemudi']) == '') {
		$error[] = '- Nama Pengemudi harus diisi !!!';
	}
	
	if ($_POST['ntotal'] <= 0) {
		$error[] = '- Periksa Total Transaksi anda !!!';
	}
}
else if ($act == 'bayar')
{
if (trim($_POST['keterangan']) == '') {
		$error[] = '- Keterangan harus diisi !!!';
	}
	if(intval($_POST['pembayaran'] > intval($_POST['kekurangan'])))
	{
		$error[] = '- Pembayaran melebihi nominal sisa pembayaran !!!';
	}

}
if (isset($error)) {
	echo "<img src=\"images/alert.png\" width=\"16\" align=\"left\"/>&nbsp;&nbsp;<b style=\"color:red;\">Error : </b> <br />".implode("<br />", $error);
}else{
	switch($act) {
	case("delete"):
		$query = "delete from gl_rtrans where no_ref='$_POST[noreferensi]'";
		$query2 = "delete from gl_trans where no_ref='$_POST[noreferensi]'";
		// hapus data
		mysql_select_db($database_con_gl, $con_gl);
		$runquery = mysql_query($query, $con_gl);
		if($runquery) { 
			// ---
			mysql_query($query2, $con_gl);
			// ---
			echo "<img src=\"images/ok.png\" align=\"left\" width=\"16\">&nbsp;&nbsp;Data berhasil dihapus ...";
			echo "<script type=\"text/javascript\">setTimeout(\"location.href='".$url."'\", 2000);</script>";
		}else{
			echo "<img src=\"images/alert.png\" align=\"left\" width=\"16\"> Data gagal dihapus !!!";
		}
	break;
	case("bayar"):
		$today = date("Y-m-d"); 
		$query = "INSERT INTO gl_pembayaran (no_ref, no_transaksi, tgl_bayar, jns_pemb, tipe_pemb, pmb_nominal, hold_status) VALUES 				                 ('$_POST[no_ref]','notrx','$today', '$_POST[cr_jenisbayar]','$_POST[cr_tipebayar]','$_POST[pembayaran]','$_SESSION[nama]' )";
		
		mysql_query("INSERT INTO gl_trans (id, kode, no_ref, transaksi, total, pos, akun) VALUES (NULL, 'KM','$_POST[no_ref]', 'Pembayaran', '$_POST[pembayaran]', 'D', '$_POST[cr_debit]')", $con_gl);
		
		mysql_query("INSERT INTO gl_trans (id, kode, no_ref, transaksi, total, pos, akun) VALUES (NULL, 'KM','$_POST[no_ref]', 'Pembayaran', '$_POST[pembayaran]', 'K', '$_POST[cr_kredit]')", $con_gl);
		
		// save data
		mysql_select_db($database_con_gl, $con_gl);
		$runquery = mysql_query($query, $con_gl) or die (mysql_error());
		if($runquery) { 
			echo "<img src=\"images/ok.png\" align=\"left\" width=\"16\">&nbsp;&nbsp;Data berhasil disimpan ...";

			echo "<script type=\"text/javascript\">window.opener.location.href='".$url."'; window.close();</script>";
		}else{
			echo "<img src=\"images/alert.png\" align=\"left\" width=\"16\"> Data gagal disimpan !!!";
		}
		
		

		
		
	break;
	case("edit"):
	// insert piutang
	if($_POST['a_piu']<>'' AND $_POST[ntotal] > 0) {
  			$nil = $_POST[ntotal];
  			mysql_select_db($database_con_gl, $con_gl);
  			if($_POST[a_piu]=='') {
  				mysql_query("INSERT INTO gl_trans (id, no_ref, transaksi, total, pos, akun) VALUES (NULL, '$_POST[noreferensi]', 'Piutang Penjualan $row_getkpd[nama]', '$_POST[ntotal]', 'D', '$_POST[a_piu]')", $con_gl);
  			}else{
				
  				mysql_query("update gl_trans set total='$nil', pos='D' where akun='$_POST[a_piu]' and no_ref='$_POST[noreferensi]' and kode='SJ'", $con_gl);
  			}
  		}else{
			if($_POST[a_piu]<>'') {
				mysql_query("delete from gl_trans where akun='$_POST[a_piu]' and no_ref='$_POST[noreferensi]'", $con_gl);
			}
		}
		
		// insert penjualan
	if($_POST['a_pend']<>'' AND $_POST[hargasatuan] > 0) {
  			
  			mysql_select_db($database_con_gl, $con_gl);
  			if($_POST[a_pend]=='') {
  				mysql_query("INSERT INTO gl_trans (id, kode,no_ref, transaksi, total, pos, akun) VALUES (NULL,'SJ', '$_POST[noreferensi]', 'Penjualan Rental Kendaraan Retail $row_getkpd[nama]', '$penj', 'K', '$_POST[a_pend]')", $con_gl) or die (mysql_error());
  			}else{
				
  				mysql_query("update gl_trans set total='$penj', pos='K' where akun='$_POST[a_pend]' and no_ref='$_POST[noreferensi]' and kode='SJ'", $con_gl);
  			}
  		}else{
			if($_POST[a_pend]<>'') {
				mysql_query("delete from gl_trans where akun='$_POST[a_pend]' and no_ref='$_POST[noreferensi]'", $con_gl);
			}
		}
		// insert PPH
	if($_POST['a_pph']<>'' AND $_POST[hargaafterpph] > 0) {
  			$query_cekpph = "SELECT akun from gl_trans where akun='$_POST[a_pph]' and no_ref ='$_POST[noreferensi]' and kode='SJ' and pos='D'";
$pph = mysql_query($query_cekpph, $con_gl) or die(mysql_error());
$cekpph = mysql_num_rows($pph);
			    			
  			if($cekpph > 0) {
				mysql_select_db($database_con_gl, $con_gl);
				echo 'update mang';
				mysql_query("update gl_trans set total='$_POST[hargaafterpph]', pos='D' where akun='$_POST[a_pph]' and no_ref='$_POST[noreferensi]' and kode='SJ'", $con_gl);
  			}else{
			    // karena pajak pph standar semua area jadi hardcode untuk delete 
				mysql_query("INSERT INTO gl_trans (id, kode,no_ref, transaksi, total, pos, akun) VALUES (NULL,'SJ', '$_POST[noreferensi]', 'Beban PPH 23', '$_POST[hargaafterpph]', 'D', '$_POST[a_pph]')", $con_gl) or die (mysql_error());
  			}
  		}else{
			mysql_query("delete from gl_trans where akun='215001' and no_ref='$_POST[noreferensi]' and kode='SJ'", $con_gl);
			
		}
		//
		// insert ppn
	if($_POST['a_paj']<>'' AND $_POST[hargaafterpph] > 0) {
  			$query_cekpph = "SELECT akun from gl_trans where akun='$_POST[a_paj]' and no_ref ='$_POST[noreferensi]' and kode='SJ' and pos='K'";
$pph = mysql_query($query_cekpph, $con_gl) or die(mysql_error());
$cekpph = mysql_num_rows($pph);
			    			
  			if($cekpph > 0) {
				mysql_select_db($database_con_gl, $con_gl);
				//echo 'update mang';
				mysql_query("update gl_trans set total='$_POST[hargaafterppn]', pos='K' where akun='$_POST[a_paj]' and no_ref='$_POST[noreferensi]' and kode='SJ'", $con_gl);
  			}else{
			    // karena pajak pph standar semua area jadi hardcode untuk delete 
				mysql_query("INSERT INTO gl_trans (id, kode,no_ref, transaksi, total, pos, akun) VALUES (NULL,'SJ', '$_POST[noreferensi]', 'Beban PPN', '$_POST[hargaafterppn]', 'K', '$_POST[a_paj]')", $con_gl) or die (mysql_error());
  			}
  		}else{
			mysql_query("delete from gl_trans where akun='117002' and no_ref='$_POST[noreferensi]' and kode='SJ'", $con_gl);
			
		}
				
	mysql_select_db($database_con_gl, $con_gl);
	
		//save email
		$addquery3 = "update gl_kontak set email = '$_POST[txtemail]' WHERE nama = '$_POST[qtxt]' ";
		$runquery3 = mysql_query($addquery3, $con_gl) or die (mysql_error());
		
	
	$today = date("Y-m-d"); 
	if($_POST['jumlah'] == '0')
		{
			$jmlhari = '1';
		} else {$jmlhari = $_POST['jumlah'];}
		$query ="UPDATE gl_retailtrans SET tgl='$_POST[tanggal]', keterangan='$_POST[keterangan]', jenis='$_POST[jenis]', area='$_POST[area]', gudang='$_POST[gudang]', barang='$_POST[barang]', kontak='$_POST[dari]', recipient='$_POST[recipient]', jatuhtempo='$_POST[checkout]', tujuan='$_POST[tujuan]', pengemudi='$_POST[txtpengemudi]', jmlhr='$jmlhari', jmlwkt='$_POST[jmlhwkt]', checkin='$_POST[checkin]', waktucheckin='$_POST[waktucheckin]', checkout='$_POST[checkout]', waktucheckout='$_POST[waktucheckout]', supir='$_POST[supir]', bbm='$_POST[bbm]', tol='$_POST[tol]', parkir='$_POST[parkir]', akomod='$_POST[akomodasi]', other='$_POST[other]', kendaraan='$_POST[kendaraan]',updated_by = '$_SESSION[nama]', updated_at = '$today' WHERE no_ref='$_POST[noreferensi]'";
		
		//rearrange index  no_book auto number in gl_book
		$queryBook2 ="DELETE FROM gl_book WHERE no_ref='$_POST[noreferensi]'";
		$runquery2 = mysql_query($queryBook2, $con_gl) or die (mysql_error());
		$queryBook3 ="ALTER TABLE gl_book DROP no_book";
		$runquery3 = mysql_query($queryBook3, $con_gl) or die (mysql_error());
		$queryBook4 ="ALTER TABLE gl_book ADD no_book BIGINT(99) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST";
		$runquery4 = mysql_query($queryBook4, $con_gl) or die (mysql_error());
		
		mysql_select_db($database_con_gl, $con_gl);
		
		
		$total = ($_POST['hargasatuan'] + $_POST['hargaafterppn'] - $_POST['diskon']); 
		if(!empty($_POST['xharga'])) {
		    $hargasatuan = $_POST['xharga'];
		}
		else
		{
			$hargasatuan = $_POST['hargasatuansebelum'];
		}
		$addquery = "UPDATE gl_detailtrans SET transaksi='$_POST[transaksi]', total='$total', barang='$_POST[barang]', kendaraan='$_POST[txtkendaraan]', ppn='$_POST[hargaafterppn]',pph='$_POST[hargaafterpph]', hargasatuan='$hargasatuan', diskon='$_POST[diskon]',diskonamount='$_POST[txtdiskon]' where no_ref = '$_POST[noreferensi]'";
	
		mysql_query($addquery, $con_gl) or die (mysql_error());
		$runquery = mysql_query($query, $con_gl) or die (mysql_error());
		if($runquery) { 
			echo "<img src=\"images/ok.png\" align=\"left\" width=\"16\">&nbsp;&nbsp;Data berhasil disimpan ...";
			echo "<script type=\"text/javascript\">setTimeout(\"location.href='".$url."'\", 2000);</script>";
		}else{
			echo "<img src=\"images/alert.png\" align=\"left\" width=\"16\"> Data gagal disimpan !!!";
		}
	break;
	default:
		mysql_select_db($database_con_gl, $con_gl);		
		

		$query_getkpd = "SELECT gl_kontak.nama FROM gl_kontak WHERE gl_kontak.id='$_POST[dari]'";
		$getkpd = mysql_query($query_getkpd, $con_gl) or die(mysql_error());
		$row_getkpd = mysql_fetch_assoc($getkpd);
		// ---
		$today = date("Y-m-d"); 
		if($_POST['jumlah'] == '0')
		{
			$jmlhari = '1';
		} else {$jmlhari = $_POST['jumlah'];}
		
		$nof = $_POST['noreferensi'];
		$encrypt_no_ref = md5($nof);
		
		$query = "INSERT INTO gl_retailtrans (no_ref, md5_no_ref, jnsorder,tgl, keterangan, area, gudang, barang, kontak, jenis, jatuhtempo, tujuan, recipient, pengemudi,  jmlhr, jmlwkt, checkin, waktucheckin, checkout, waktucheckout, supir, bbm, tol, parkir, akomod, other, kendaraan,created_by,created_at,status) VALUES ('$_POST[noreferensi]','$encrypt_no_ref','0', '$_POST[tanggal]', '$_POST[keterangan]', '$_POST[area]', '$_POST[gudang]', '$_POST[barang]', '$_POST[dari]', '$_POST[jenis]', '$_POST[checkout]','$_POST[tujuan]', '$_POST[recipient]', '$_POST[txtpengemudi]','$jmlhari','$_POST[jmlhwkt]','$_POST[checkin]', '$_POST[waktucheckin]', '$_POST[checkout]', '$_POST[waktucheckout]', '$_POST[supir]', '$_POST[bbm]', '$_POST[tol]', '$_POST[parkir]', '$_POST[akomodasi]', '$_POST[other]','$_POST[kendaraan]','$_SESSION[nama]','$today','0')";
		// [ Jurnal Penjualan ]
		// insert piutang
		
		if($_POST['a_piu']<>'' AND $_POST['ntotal'] > 0) {
  			//$nil = $_POST['ntotal'];
  		$nil = (int)$_POST['hargasatuan'] + (int)$_POST['hargaafterppn'] + (int)$_POST['biaya'] - (int)$_POST['hargaafterpph'];
			mysql_select_db($database_con_gl, $con_gl); 
 			mysql_query("INSERT INTO gl_trans (id, kode,no_ref, transaksi, total, pos, akun) VALUES (NULL,'SJ', '$_POST[noreferensi]', 'Piutang Penjualan $row_getkpd[nama]', '$nil', 'D', '$_POST[a_piu]')", $con_gl) or die (mysql_error());
  		}
		// penjualan 
		
		if($_POST['a_pend']<>'' AND $_POST['hargasatuan'] > 0) {
  			$penj = $_POST['hargasatuan'] + (int)$_POST['txtdiskon'];
  			mysql_select_db($database_con_gl, $con_gl); 
 			mysql_query("INSERT INTO gl_trans (id, kode,no_ref, transaksi, total, pos, akun) VALUES (NULL,'SJ', '$_POST[noreferensi]', 'Penjualan Rental Kendaraan Retail $row_getkpd[nama]', '$penj', 'K', '$_POST[a_pend]')", $con_gl) or die (mysql_error());
  		}
		// Potongan
		if($_POST['a_potongan']<>'' AND $_POST['txtdiskon'] > 0) {
  			$potongan = $_POST['txtdiskon'];
  			mysql_select_db($database_con_gl, $con_gl); 
 			mysql_query("INSERT INTO gl_trans (id, kode,no_ref, transaksi, total, pos, akun) VALUES (NULL,'SJ', '$_POST[noreferensi]', 'Potongan Penjualan [Diskon] $row_getkpd[nama]', '$potongan', 'D', '$_POST[a_potongan]')", $con_gl) or die (mysql_error());
  		}
		// insert PPH
		if($_POST[a_pph] <>'' AND $_POST[hargaafterpph] > 0) {
  			mysql_select_db($database_con_gl, $con_gl);
  			mysql_query("INSERT INTO gl_trans (id, kode,no_ref, transaksi, total, pos, akun) VALUES (NULL,'SJ', '$_POST[noreferensi]', 'Beban PPH 23', '$_POST[hargaafterpph]', 'D', '$_POST[a_pph]')", $con_gl) or die (mysql_error());
 		}
			// insert pajak
  		if($_POST[a_paj] <>'' AND $_POST[hargaafterppn] > 0) {
  			mysql_select_db($database_con_gl, $con_gl); 
 			mysql_query("INSERT INTO gl_trans (id, kode,no_ref, transaksi, total, pos, akun) VALUES (NULL,'SJ', '$_POST[noreferensi]', 'Beban PPN', '$_POST[hargaafterppn]', 'K', '$_POST[a_paj]')", $con_gl) or die (mysql_error());
  		}
		// insert tol parkir
		$biaya = (int)$_POST[tol] + (int)$_POST[parkir];
		if($_POST[a_beb] <>'' AND $biaya > 0) {
			$biaya = (int)$_POST[tol] + (int)$_POST[parkir];
  			mysql_select_db($database_con_gl, $con_gl);
  			mysql_query("INSERT INTO gl_trans (id, kode,no_ref, transaksi, total, pos, akun) VALUES (NULL,'SJ', '$_POST[noreferensi]', 'Beban Biaya Lain [Tol Parkir]', '$biaya', 'K', '$_POST[a_beb]')", $con_gl) or die (mysql_error());
 		}
		// insert tol bbm
		if($_POST[a_bbm] <>'' AND $_POST[bbm] > 0) {
			
  			mysql_select_db($database_con_gl, $con_gl);
  			mysql_query("INSERT INTO gl_trans (id, kode,no_ref, transaksi, total, pos, akun) VALUES (NULL,'SJ', '$_POST[noreferensi]', 'Beban Biaya BBM', '$_POST[bbm]', 'K', '$_POST[a_bbm]')", $con_gl) or die (mysql_error());
 		}
		// insert akomodasi a_jasadriver
			if($_POST[a_jasadriver] <>'' AND $_POST[supir] > 0) {
			
  			mysql_select_db($database_con_gl, $con_gl);
  			mysql_query("INSERT INTO gl_trans (id, kode,no_ref, transaksi, total, pos, akun) VALUES (NULL,'SJ', '$_POST[noreferensi]', 'Beban Biaya Jasa Driver', '$_POST[supir]', 'K', '$_POST[a_jasadriver]')", $con_gl) or die (mysql_error());
 		}
	    // insert akomodasi / uang makan
		if($_POST[a_insentifdriver] <>'' AND $_POST[akomodasi] > 0) {
			
  			mysql_select_db($database_con_gl, $con_gl);
  			mysql_query("INSERT INTO gl_trans (id, kode,no_ref, transaksi, total, pos, akun) VALUES (NULL,'SJ', '$_POST[noreferensi]', 'Beban Biaya Uang Makan', '$_POST[akomodasi]', 'K', '$_POST[a_insentifdriver]')", $con_gl) or die (mysql_error());
 		}
		// Jurnal Biaya Operasional
		// Kas Kecil di kredit, pengurangan
		if($_POST[biaya] > 0)
		{
		if($_POST[a_kaskecil] <>'' AND $_POST[biaya]) {
			$totbiaya = (int)$_POST[biaya];
  			mysql_select_db($database_con_gl, $con_gl);
  			mysql_query("INSERT INTO gl_trans (id, kode,no_ref, transaksi, total, pos, akun) VALUES (NULL,'KK', '$_POST[noreferensi]', 'Kas Kecil', '$totbiaya', 'K', '$_POST[a_kaskecil]')", $con_gl) or die (mysql_error());
 		}
		// 
		$biaya = (int)$_POST[tol] + (int)$_POST[parkir];
		if($_POST[a_beb] <>'' AND $biaya > 0) {
			$biaya = (int)$_POST[tol] + (int)$_POST[parkir];
  			mysql_select_db($database_con_gl, $con_gl);
  			mysql_query("INSERT INTO gl_trans (id, kode,no_ref, transaksi, total, pos, akun) VALUES (NULL,'KK', '$_POST[noreferensi]', 'Beban Biaya Lain [Tol Parkir]', '$biaya', 'D', '$_POST[a_beb]')", $con_gl) or die (mysql_error());
 		}
		// insert tol bbm
		if($_POST[a_bbm] <>'' AND $_POST[bbm] > 0) {
			
  			mysql_select_db($database_con_gl, $con_gl);
  			mysql_query("INSERT INTO gl_trans (id, kode,no_ref, transaksi, total, pos, akun) VALUES (NULL,'KK', '$_POST[noreferensi]', 'Beban Biaya BBM', '$_POST[bbm]', 'D', '$_POST[a_bbm]')", $con_gl) or die (mysql_error());
 		}
		// insert akomodasi a_jasadriver
			if($_POST[a_jasadriver] <>'' AND $_POST[supir] > 0) {
			
  			mysql_select_db($database_con_gl, $con_gl);
  			mysql_query("INSERT INTO gl_trans (id, kode,no_ref, transaksi, total, pos, akun) VALUES (NULL,'KK', '$_POST[noreferensi]', 'Beban Biaya Jasa Driver', '$_POST[supir]', 'D', '$_POST[a_jasadriver]')", $con_gl) or die (mysql_error());
 		}
	    // insert akomodasi / uang makan
		if($_POST[a_insentifdriver] <>'' AND $_POST[akomodasi] > 0) {
			
  			mysql_select_db($database_con_gl, $con_gl);
  			mysql_query("INSERT INTO gl_trans (id, kode,no_ref, transaksi, total, pos, akun) VALUES (NULL,'KK', '$_POST[noreferensi]', 'Beban Biaya Uang Makan', '$_POST[akomodasi]', 'D', '$_POST[a_insentifdriver]')", $con_gl) or die (mysql_error());
 		}
		}
		else 
		{
			// tidak ada aktifitas
		}
		// tambah variable grandtotal	
  			
		mysql_select_db($database_con_gl, $con_gl);
		
		//save email
		$addquery3 = "update gl_kontak set email = '$_POST[txtemail]' WHERE nama = '$_POST[qtxt]' ";
		$runquery3 = mysql_query($addquery3, $con_gl) or die (mysql_error());
		
		// save data
		$addquery = "INSERT INTO gl_detailtrans (id, no_ref, transaksi, total, barang, kendaraan, ppn,pph, hargasatuan, diskon,diskonamount) VALUES (NULL, '$_POST[noreferensi]', '$_POST[transaksi]', '$_POST[hargasatuan]', '$_POST[barang]', '$_POST[kendaraan]', '$_POST[hargaafterppn]','$_POST[hargaafterpph]','$_POST[xharga]', '$_POST[diskon]','$_POST[txtdiskon]')";
		mysql_query($addquery, $con_gl) or die (mysql_error());
		mysql_select_db($database_con_gl, $con_gl);
		$runquery = mysql_query($query, $con_gl) or die (mysql_error());
		if($runquery) { 
			echo "<img src=\"images/ok.png\" align=\"left\" width=\"16\">&nbsp;&nbsp;Data berhasil disimpan ...";
			echo "<script type=\"text/javascript\">setTimeout(\"location.href='".$url."'\", 2000);</script>";
		}else{
			echo "<img src=\"images/alert.png\" align=\"left\" width=\"16\"> Data gagal disimpan !!!";
		}
		
		
		
		mysql_select_db($database_con_gl, $con_gl);
 		$customer = mysql_query("SELECT tlp,email from gl_kontak WHERE nama = '$_POST[qtxt]' AND type = 'Customer' ", $con_gl) or die(mysql_error());
		$row_customer = mysql_fetch_assoc($customer);
		
		//email konfirmasi
		$mail = new PHPMailer();

		$mail->isSMTP();

		$mail->SMTPAuth = TRUE;
		$mail->SMTPSecure = 'ssl'; //tls or ssl

		//$mail->Host = 'smtp.gmail.com';
		//$mail->Host = 'smtp.googlemail.com';
		$mail->Host = 'mail.cipaganti.co.id';

		//ssl -> 465; tls -> 587
		$mail->Port = 465;

		/**
		 * konfigurasi email pengirim
		 */

		$mail->Username = 'rentcar@cipaganti.co.id';
		$mail->Password = 'r1k1g4nt3n6';
		$mail->From = 'rentcar@cipaganti.co.id';
		/*
		$mail->Username = 'deryfath@gmail.com';
		$mail->Password = 'hiduprefac';
		$mail->From = 'deryfath@gmail.com';
		*/
		$mail->FromName = "RENTCAR CIPAGANTI";

		/**
		 * konfigurasi email penerima
		 */
		$mail->AddAddress($_POST['txtemail'], 'Dery');
		$mail->AddCC('mricky.it@gmail.com','Dede');
		/**
		 * konfigurasi pesan
		 */
		$checkin = date('d F Y', strtotime($_POST['checkin']));
		$checkout = date('d F Y', strtotime($_POST['checkout']));
		
		/*
		//kirim via session
		$_SESSION['noref'] = $_POST['noreferensi'];
		$_SESSION['nama'] = $_POST['qtxt'];
		$_SESSION['tlp'] = $row_customer['tlp'];
		$_SESSION['kendaraan'] = $_POST['kendaraan'];
		$_SESSION['barang'] = $_POST['txtbarang'];
		$_SESSION['checkin'] = $checkin;
		$_SESSION['checkout'] = $checkout;
		$_SESSION['cabang'] = $_POST['txtcabang'];
		$_SESSION['transaksi'] = $_POST['transaksi'];
		*/
		
		$mail->isHTML(true);
		$mail->Subject = 'TICKETING CONFIRMATION';
		//$url = "http://localhost/rental/proses/mailer.php/$_POST[noreferensi]/$_POST[qtxt]/$row_customer[tlp]/$_POST[kendaraan]/$_POST[txtbarang]/$checkin/$checkout/$_POST[txtcabang]/$_POST[transaksi]";
		//$url = "http://118.97.213.239/cipaganti-rentcar/proses/mailer.php?asd=$encrypt_no_ref";
		$url = "http://localhost/cipaganti-rentcar/proses/mailer.php?asd=$encrypt_no_ref";
		//$url = "http://192.168.112.243/rental/proses/mailer.php/";
		$mail->AddEmbeddedImage('images/button.png', 'button', 'images/button.png');
		$myBody = "<html>";
		$myBody .= "<head>";
		$myBody .= "<title>TICKETING CONFIRMATION</title>";
		//$myBody .= "<link href=\"button.css\" rel=\"stylesheet\" type=\"text/css\" />";
		$myBody .= "</head>";
		$myBody .= "<body>";
		$myBody .= "<table width=\"600\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">";
		$myBody .= "<tr>";
		$myBody .= "<td align=\"center\" valign=\"middle\" bgcolor=\"#000000\" style=\"background-color:#000000; padding:20px; color:#ffffff;\">";
		$myBody .= "<div style=\"font-size:24px;\">CIPAGANTI CAR RENTAL</div>";
		$myBody .= "</td>";
		//$myBody .= "<td align=\"right\" valign=\"top\"><img src=\"cid:logoimg\" width=\"197\" height=\"182\" style=\"display:block;\"></td>";
		$myBody .= "</tr>";
		$myBody .= "</table>";
		$myBody .= "<table width=\"600\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"1\" bgcolor=\"#971800\" style=\"background-color:#971800;\">";
		$myBody .=  "<tr>";
		$myBody .= 		"<td align=\"center\" valign=\"middle\" bgcolor=\"#971800\" style=\"background-color:#971800; padding:4px; color:#fc9600;\">";
		$myBody .= 		"<div style=\"font-size:14px;\"><b>CAR BOOKING CONFIRMATION<b></div>";
		$myBody .= 		"</td>";
		$myBody .=	"</tr>";
		$myBody .=	"<tr>";
		$myBody .=	"<td align=\"left\" valign=\"top\" bgcolor=\"#e7e0b7\" style=\"background-color:#e7e0b7; padding:20px;\"><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"10\" style=\"margin-bottom:10px;\">";
		$myBody .=		"<div style=\"font-size:14px; color:#000000;\">";
		$myBody .=		"Dear CIPAGANTI, Thank you for choosing Tiket.com as your online ticketing & booking partner! <br><br> This is just to inform you that the following customer with Tiket.com's Order ID #22013019 and Item Number 11784716 has booked a car. <br><br>
						Kindly reserve the booking of our customers and allotment in your TiketConnect module.<br><br>
						Here is your guest reservation information:</div><br>";
		$myBody .=		"<hr align=\"center\"><br>";
		$myBody .=		"<div style=\"font-size:14px;  color:#000000\"> ";
		$myBody .=		"<pre><font face =\"Arial\"><b>Guest Name</b>		: $_POST[qtxt] </font></pre>
						<pre><font face =\"Arial\"><b>Phone</b> 			: $row_customer[tlp] </font></pre> 
						<pre><font face =\"Arial\"><b>Car Name</b> 		: $_POST[kendaraan] </font></pre>
						<pre><font face =\"Arial\"><b>Service Type</b>		: $_POST[txtbarang] </font></pre>
						<pre><font face =\"Arial\"><b>Pick Up</b>			: $checkin </font></pre>
						<pre><font face =\"Arial\"><b>Drop Off</b> 			: $checkout </font></pre>
						<pre><font face =\"Arial\"><b>Regional Area </b>	: $_POST[txtcabang] </font></pre>
						<pre><font face =\"Arial\"><b>Pick Up Detail</b>	 	: $_POST[transaksi] </font></pre></div><br>";
		
		$myBody .=		"<hr align=\"center\"><br>";
		$myBody .=		"<div style=\"font-size:14px; color:#000000;\">";
		$myBody .=		"Please confirm that you have received this booking by click submit button below..</div><br>";
		$myBody .= 	 	"<div align=\"center\" ><a href=\"$url\"><img src=\"cid:button\" style=\"display:block;\"></a></div>";
		
		$myBody .= 	 	"</td>";
		$myBody .= 	  "</tr>";
		$myBody .= 	  "</table>";
		
		$myBody .= "</body>";
		$myBody .= "</html>";

		$mail->Body = $myBody;
		//$mail->AltBody = $_POST['email_body'];
		//$mail->msgHTML(file_get_contents('mailer.html'), dirname(__FILE__));
		if (!$mail->Send()) {
			$output = json_encode(array("message" => "Mailer Error: " . $mail->ErrorInfo));
			die($output);
			exit;
		}
		
		$output = json_encode(array("message" => "Email telah terkirim.. ".$_POST['txtemail']));
		die($output);
		
		
	break;
	}
}
?>